/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import java.util.List;
import Modelo.*;
import Modelo.Clases.*;
import javax.swing.JOptionPane;

/**
 *
 * @author cltsmalc
 */
public class FamiliarJPanel extends javax.swing.JPanel {

    /**
     * Creates new form FamiliarJPanel
     */
    
    
    public FamiliarJPanel() {
        initComponents();
    }
    
    public FamiliarJPanel(int width , int height) {
        initComponents();
         this.setSize(width, height);
        this.setVisible(true);
        
        
         List<Familiar> lista = Modelo.consultarFamiliares();
        
         for(int i =0 ; i < lista.size();i++){

            
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getParentesco(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
            
        }
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jEImagePanel1 = new recursos.JEImagePanel();
        jTextField7 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField(5);
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField8 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField(5);
        jButton5 = new javax.swing.JButton();

        jEImagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/magic-wind-blue.jpg"))); // NOI18N

        jTextField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField7ActionPerformed(evt);
            }
        });

        jLabel6.setText("Genero:");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "activo", "inactivo","eliminado" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        jLabel1.setText("Nombre:");

        jLabel11.setText("Anciano:");

        jTextField1.setMaximumSize(new java.awt.Dimension(0,0));
        jTextField1.setMinimumSize(new java.awt.Dimension(0,0));
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "masculino", "femenino" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Add.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel8.setBackground(new java.awt.Color(204, 255, 153));
        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel8.setForeground(new java.awt.Color(102, 102, 255));
        jLabel8.setText("Ingreso de Familiar");

        jLabel12.setText("Estado:");

        jLabel2.setText("Apellido:");

        jLabel3.setText("Parentesco:");

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });
        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField3KeyTyped(evt);
            }
        });

        jLabel4.setText("Cedula:");

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });
        jTextField6.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField6KeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField6KeyTyped(evt);
            }
        });

        jLabel7.setText("Correo:");

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Trash_Delete.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nombre", "Apellido", "Cedula", "Parentesco", "Estado"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTextField8.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField8KeyReleased(evt);
            }
        });

        jButton2.setText("Seleccionar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField2.setMaximumSize(new java.awt.Dimension(0,0));
        jTextField2.setMinimumSize(new java.awt.Dimension(0,0));
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField2KeyTyped(evt);
            }
        });

        jButton5.setBackground(new java.awt.Color(255, 255, 255));
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/buscar.png"))); // NOI18N

        javax.swing.GroupLayout jEImagePanel1Layout = new javax.swing.GroupLayout(jEImagePanel1);
        jEImagePanel1.setLayout(jEImagePanel1Layout);
        jEImagePanel1Layout.setHorizontalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jButton1))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jEImagePanel1Layout.createSequentialGroup()
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel11))
                                .addGap(18, 18, 18)
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField7)
                                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField6)
                                    .addComponent(jComboBox3, 0, 233, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jEImagePanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(19, 19, 19)
                                .addComponent(jTextField3))
                            .addComponent(jLabel8)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1))
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                        .addGap(19, 19, 19)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE))
                                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)))))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 577, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addComponent(jButton4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton3)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(76, 76, 76))))
        );
        jEImagePanel1Layout.setVerticalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(22, 22, 22)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2)
                            .addComponent(jLabel11))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(56, 56, 56)
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton4)
                    .addComponent(jButton1)
                    .addComponent(jButton3))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jTextField7ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox3ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed

    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true || jTextField1.getText().length() >= 10) {
            evt.consume();
        }

    }//GEN-LAST:event_jTextField1KeyTyped

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      
        
        try{
            Familiar f = new Familiar();
               f.setNombre(jTextField1.getText());
                f.setApellido(jTextField2.getText());
                f.setCedula(jTextField3.getText());
                f.setParentesco(jTextField6.getText());
                f.setCorreo(jTextField7.getText());
                f.setGenero(jComboBox1.getSelectedItem().toString());
                f.setEstado(jComboBox3.getSelectedItem().toString());
                
                    
              if(v.anciano.getIdAnciano() != null){
              
                  f.setIdAnciano(v.anciano.getIdAnciano());
                  Modelo.guardar(f);
                  initComponents();
       
         
         List<Familiar> lista = Modelo.consultarFamiliares();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         for(int i =0 ; i < lista.size();i++){
           this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getParentesco(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
           
        }
         this.setVisible(true);
         JOptionPane.showMessageDialog(null, "Registro Correcto");
                  
                  
              }else{
              
                  JOptionPane.showMessageDialog(null, "Elija un Anciano");
              }
            
            
        }catch(Exception e){
        
            JOptionPane.showMessageDialog(null, "Datos incorrectos");
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyTyped
        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9') || jTextField3.getText().length() >= 10)
                && (caracter != '\b' /*
                 * corresponde a BACK_SPACE
                 */)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_jTextField3KeyTyped

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jTextField6KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField6KeyPressed

    }//GEN-LAST:event_jTextField6KeyPressed

    private void jTextField6KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField6KeyTyped
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true || jTextField6.getText().length() >= 10) {
            evt.consume();
        }
    }//GEN-LAST:event_jTextField6KeyTyped

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
        
        Familiar f = Modelo.consultarFamiliar(jTable1.getValueAt(jTable1.getSelectedRow(), 2)+"");
        
        if(f != null){
        
            Modelo.eliminar(f);
             initComponents();
       
         
         List<Familiar> lista = Modelo.consultarFamiliares();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         for(int i =0 ; i < lista.size();i++){
           this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getParentesco(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
           
        }
         this.setVisible(true);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    int bandera = 0 ;
    int id = -1 ;
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed

        try{
            if(bandera == 0 ){
                Familiar f = Modelo.consultarFamiliar(jTable1.getValueAt(jTable1.getSelectedRow(), 2)+"");
                if(f != null){
                
                   id = f.getIdFamiliar() ;
                   jTextField1.setText(f.getNombre());
                   jTextField2.setText(f.getApellido());
                   jTextField3.setText(f.getCedula());
                   jTextField6.setText(f.getParentesco());
                   jTextField7.setText(f.getCorreo());
                   if(f.getGenero().equalsIgnoreCase("masculino")){
                        this.jComboBox1.setSelectedIndex(0);
                        }
                     if(f.getGenero().equalsIgnoreCase("femenino")){
                        this.jComboBox1.setSelectedIndex(1);
                         }
            
                    
                     if(f.getEstado().equalsIgnoreCase("eliminado")){
                         this.jComboBox3.setSelectedIndex(2);
                            }
                     if(f.getEstado().equalsIgnoreCase("inactivo")){
                         this.jComboBox3.setSelectedIndex(1);
                              }
                    if(f.getEstado().equalsIgnoreCase("activo")){
                         this.jComboBox3.setSelectedIndex(0);
                               }
                    
                    bandera = 1 ;
                    jLabel8.setText("Modificar");
                     jButton1.setEnabled(false);
                     jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/guardar.png")));
                    
                }else{
                JOptionPane.showMessageDialog(null, "Error al cargar los datos");
                }
        
        
            }else{
                
                Familiar f = Modelo.consultarFamiliar(id);
                
                f.setNombre(jTextField1.getText());
                f.setApellido(jTextField2.getText());
                f.setCedula(jTextField3.getText());
                f.setParentesco(jTextField6.getText());
                f.setCorreo(jTextField7.getText());
                f.setGenero(jComboBox1.getSelectedItem().toString());
                f.setEstado(jComboBox3.getSelectedItem().toString());
                
                    try{
              if(v.anciano.getIdAnciano() != null){
              
                  f.setIdAnciano(v.anciano.getIdAnciano());
                  
              }
                  }catch(Exception e){
                  
                  }
                
                Modelo.actualizar(f);
                
                
             initComponents();
       
         
         List<Familiar> lista = Modelo.consultarFamiliares();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         for(int i =0 ; i < lista.size();i++){
           this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getParentesco(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
           
        }
         this.setVisible(true);
         
         
         bandera = 0 ;
         jButton1.setEnabled(true);
         jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png")));
         jLabel8.setText("Ingresar Familiar");
         JOptionPane.showMessageDialog(null, "Registro Acualizado correctamente");
                
                
                
            
            }
            
        
        
        
        }catch(Exception e){
        
        }
        
    }//GEN-LAST:event_jButton4ActionPerformed
Seleccionar v ;
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
     v = new Seleccionar();
    v.setVisible(true);
}//GEN-LAST:event_jButton2ActionPerformed

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField2ActionPerformed

private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_jTextField2KeyTyped

private void jTextField8KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField8KeyReleased
// TODO add your handling code here:
    
    String c = this.jTextField8.getText();
    
    List<Familiar> lista = Modelo.consultarFamiliaresCoincidencias(c);
    
    for(int i = 0 ; i < jTable1.getRowCount(); i++){
    
        this.jTable1.setValueAt("", i, 0);
        this.jTable1.setValueAt("", i, 1);
        this.jTable1.setValueAt("", i, 2);
        this.jTable1.setValueAt("", i, 3);
        this.jTable1.setValueAt("", i, 4);
    }
    
    for(int i = 0 ; i < lista.size(); i++){
    
        this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
        this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
        this.jTable1.setValueAt(lista.get(i).getCedula(), i, 2);
        this.jTable1.setValueAt(lista.get(i).getParentesco(), i, 3);
        this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
    }
}//GEN-LAST:event_jTextField8KeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox3;
    private recursos.JEImagePanel jEImagePanel1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    // End of variables declaration//GEN-END:variables
}
